﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Thinker.SignChannel.Migrations
{
    /// <inheritdoc />
    public partial class InitialApp : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "AppPeople",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "TEXT", nullable: false),
                    PersonName = table.Column<string>(type: "TEXT", maxLength: 256, nullable: false),
                    IdNumber = table.Column<string>(type: "TEXT", maxLength: 32, nullable: false),
                    Sex = table.Column<string>(type: "TEXT", maxLength: 8, nullable: true),
                    PersonCode = table.Column<string>(type: "TEXT", maxLength: 32, nullable: true),
                    PersonType = table.Column<string>(type: "TEXT", maxLength: 64, nullable: true),
                    ExtraProperties = table.Column<string>(type: "TEXT", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "TEXT", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "TEXT", nullable: false),
                    CreatorId = table.Column<Guid>(type: "TEXT", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "TEXT", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AppPeople", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "AppTimes",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "TEXT", nullable: false),
                    SignDate = table.Column<DateOnly>(type: "TEXT", nullable: false),
                    Period = table.Column<string>(type: "TEXT", maxLength: 256, nullable: false),
                    Direction = table.Column<int>(type: "INTEGER", nullable: false),
                    SignTime = table.Column<DateTime>(type: "TEXT", nullable: false),
                    SignBegin = table.Column<DateTime>(type: "TEXT", nullable: false),
                    SignEnd = table.Column<DateTime>(type: "TEXT", nullable: false),
                    ExtraProperties = table.Column<string>(type: "TEXT", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "TEXT", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "TEXT", nullable: false),
                    CreatorId = table.Column<Guid>(type: "TEXT", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "TEXT", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AppTimes", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "AppPersonTimes",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "TEXT", nullable: false),
                    PersonId = table.Column<Guid>(type: "TEXT", nullable: false),
                    TimeId = table.Column<Guid>(type: "TEXT", nullable: false),
                    RecordId = table.Column<Guid>(type: "TEXT", nullable: true),
                    SignResult = table.Column<int>(type: "INTEGER", nullable: false),
                    LeaveReason = table.Column<string>(type: "TEXT", nullable: true),
                    ExtraProperties = table.Column<string>(type: "TEXT", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "TEXT", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "TEXT", nullable: false),
                    CreatorId = table.Column<Guid>(type: "TEXT", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "TEXT", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AppPersonTimes", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AppPersonTimes_AppPeople_PersonId",
                        column: x => x.PersonId,
                        principalTable: "AppPeople",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_AppPersonTimes_AppTimes_TimeId",
                        column: x => x.TimeId,
                        principalTable: "AppTimes",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "AppRecords",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "TEXT", nullable: false),
                    IdNumber = table.Column<string>(type: "TEXT", nullable: false),
                    PersonName = table.Column<string>(type: "TEXT", nullable: false),
                    RecordTime = table.Column<DateTime>(type: "TEXT", nullable: false),
                    PersonId = table.Column<Guid>(type: "TEXT", nullable: true),
                    TimeId = table.Column<Guid>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AppRecords", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AppRecords_AppPeople_PersonId",
                        column: x => x.PersonId,
                        principalTable: "AppPeople",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_AppRecords_AppTimes_TimeId",
                        column: x => x.TimeId,
                        principalTable: "AppTimes",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateIndex(
                name: "IX_AppPeople_IdNumber",
                table: "AppPeople",
                column: "IdNumber");

            migrationBuilder.CreateIndex(
                name: "IX_AppPersonTimes_PersonId_TimeId",
                table: "AppPersonTimes",
                columns: new[] { "PersonId", "TimeId" });

            migrationBuilder.CreateIndex(
                name: "IX_AppPersonTimes_TimeId",
                table: "AppPersonTimes",
                column: "TimeId");

            migrationBuilder.CreateIndex(
                name: "IX_AppRecords_PersonId_TimeId",
                table: "AppRecords",
                columns: new[] { "PersonId", "TimeId" });

            migrationBuilder.CreateIndex(
                name: "IX_AppRecords_TimeId",
                table: "AppRecords",
                column: "TimeId");

            migrationBuilder.CreateIndex(
                name: "IX_AppTimes_SignDate_Period_Direction",
                table: "AppTimes",
                columns: new[] { "SignDate", "Period", "Direction" });
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "AppPersonTimes");

            migrationBuilder.DropTable(
                name: "AppRecords");

            migrationBuilder.DropTable(
                name: "AppPeople");

            migrationBuilder.DropTable(
                name: "AppTimes");
        }
    }
}
